#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <tchar.h>

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
    BOOL goon                = TRUE;
    TCHAR winClass[MAX_PATH] = {0};
    int ret                  = GetClassName(hwnd, winClass, MAX_PATH);
    if(0 == ret)
    {
        return goon;
    }

    if(0 == lstrcmp(_T("si_Frame"), winClass))
    {
        /*
         *hwnd = FindWindowEx(hwnd, NULL, _T("MDIClient"), NULL);
         *if(hwnd)
         */
        {
            printf("bingo, 0x%p\n", hwnd);
            *((HWND*)lParam) = hwnd;
            goon = FALSE;
        }
    }
    return goon;
}


extern int InjectDll(HWND hWnd);
extern int UnmapDll(HWND hWnd);

int main(int argc, char const* argv[])
{
    HWND hWnd = NULL;

    EnumWindows(EnumWindowsProc, (LPARAM)&hWnd);
    if (!hWnd)
    {
        printf("no expected window for now\n");
        return 1;
    }
    if (argc == 1)
    {
        InjectDll(hWnd);
    }
    else
    {
        UnmapDll(hWnd);
    }
    return 0;
}
